package com.zcx.merchantorder.util;

import com.zcx.merchantorder.entity.MessageEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * @Description: EventBus组件间通信工具
 * @Author: zcx
 * @CreateDate: 2019/3/3 13:56
 */
public class EventBusUtils {

    /**
     *注册 EventBus
     * @date: 2019/3/3 14:01
     * @author: zcx
     * @param subscriber
     * @return void
     */
    public static void register(Object subscriber) {
        EventBus.getDefault().register(subscriber);
    }

    /**
    *解除注册 EventBus
     * @date: 2019/3/3 14:01
     * @author: zcx
     * @param subscriber
     * @return void
     */
    public static void unregister(Object subscriber) {
        if (EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().unregister(subscriber);
        }
    }

    /**
    *发送事件消息
     * @date: 2019/3/3 14:01
     * @author: zcx
     * @param baseEvent
     * @return void
     */
    public static void post(MessageEvent baseEvent) {
        EventBus.getDefault().post(baseEvent);
    }

    /**
    *发送粘性事件消息
     * @date: 2019/3/3 14:01
     * @author: zcx
     * @param baseEvent
     * @return void
     */
    public static void postSticky(MessageEvent baseEvent) {
        EventBus.getDefault().postSticky(baseEvent);
    }
}
